<template>
    <view>
        <!--一键填报选择-->
		<uni-popup id="selSummary" ref="dialogSummary" type="dialog">
			<view style="width: 100%; background: #fff; padding: 5px 20px; border-radius: 15px;box-sizing:border-box" class="createPop">
				<view style="text-align: center; margin: 15px 0px; color: #007aff; font-size: 18px; font-weight: 600"> 项目情况总结 </view>
				<form style="font-size: 14px">
					<view style="min-height: 200px; max-height: 500px; overflow-y: scroll;">
						<view class="uni-padding-wrap" style=" margin-bottom: 10px">
							<view class="uni-title uni-common-mt" style="font-size: 16px">相关项目：</view>
						</view>
						<view class="uni-list" style="border-top: 1px solid #ddd; max-height: 300px">
                            <view v-for="p, i in lastRecord" :key="p.name" class="uni-form-item uni-column; " 
                                style="min-height: 40px; display: flex; flex-direction: row; border-bottom: 1px solid #ddd">
								<view class="uni-padding-wrap" style="width: 100%">
									<view class="uni-title" style="height: 40px; line-height: 40px; font-weight: 600">{{i + 1}}.{{p.name}}</view>
										<view style="margin-bottom: 15px; font-size: 13px">
											<radio-group @change="radioChange(p, $event)">
												<label class="radio" style="margin: 0px 50px"><radio value="0" :checked="!p.over" />无逾期</label>
												<label class="radio"><radio value="1" :checked="p.over" />有逾期</label>
											</radio-group>
										</view>
										<textarea placeholder="逾期原因及措施，无逾期可不填" v-model="p.desp" class="textInput"></textarea>
								</view>
                            </view>
						</view>
					</view>
					<view style="padding:3px 0px 0px 0px; font-size: 13px; font-family: cursive;">注：每日仅需总结一次，点击确定将覆盖</view>
					<view style="text-align: center; display: flex; justify-content: space-between; padding: 15px 25px; flex-direction: row;">
						<button class="mini-btn" type="default" size="mini" @click="cancel">取消</button>
						<button class="mini-btn" type="primary" size="mini" @click="submit">确认</button>
					</view>
				</form>
			</view>
		</uni-popup>

    </view>

</template>


<script>
	import {Numbers} from "../../../js/base";
	import Utils from '../../js/utils';

	export default {
        name: 'Popup',
        props: ['selDayLog', 'lastRecord', 'lastDay'],
		components: {
			// uniBadge,
			// uniList,
			// uniIcons
		},
		data() {
			return {
				textOver: "因…导致逾期，",
				textNorm: "与原计划相符，无逾期。"
            }
        }, 
        computed: {

        },
        methods: {
			isDefault(p) {
				if (p.desp.trim() == "") return true;
				if (p.over && p.desp.trim() == this.textOver) return true;
				if (!p.over && p.desp.trim() == this.textNorm) return true;
				return false;
			}, 
			radioChange (p, e) {
				let flag = (e.target.value == "0") ? false : true;
				if (flag && this.isDefault(p)) p.desp = this.textOver;
				if (!flag && this.isDefault(p)) p.desp = this.textNorm;
				this.$set(p, "over", flag);
			},
            cancel () {
				this.$refs.dialogSummary.close();
            },
            submit () {
				let es = this.lastRecord.filter(d => d.over && this.isDefault(d));
				if (es.length > 0) uni.showToast({title: '请核查项目进度与描述是否相符！', duration: 4000});
				let err = false;
				// 各项目拼接生成文本
				let ts = this.lastRecord.map((d, i) => {
					if (!d.over && this.isDefault(d)) d.desp = this.textNorm;
					let ps = d.content.split("\n");
					if (ps[ps.length - 1].substr(0, 3) == "总结：") err = true;
					let txt = `${Numbers[i]}、${d.name}\n${d.content}\n总结：${d.desp}\n`;
					return txt;
				})
				if (err) {
					return uni.showToast({title: '检测到原内容存在总结，请刷新界面，或手动处理！', duration: 4000});
				}
				let record = ts.join("");
				this.$emit('submit', record);
				this.$refs.dialogSummary.close();
				Utils.setCacheSync("lastDay", this.lastDay);
            }
        }
    }
</script>

<style>
.textInput{
		width: 100% !important; font-family: cursive; height: 50px;
		font-size: 13px; line-height: 120%; padding: 0px 5px; 
}
</style>
